package com.app.util.common;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

public class ApacheUploadUtil {

	Map<String,String> pro_formField = new HashMap<String,String>();
	Map<String,MultipartFile> pro_uploadField = new HashMap<String,MultipartFile>();
	public ApacheUploadUtil(HttpServletRequest request){
		try{

			MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
			
			//文件对象
			MultipartFile file=multiRequest.getFile("objFile");
			//移动端传过来名称转换为了temp，而不是objFile
			if(file == null){
				file = multiRequest.getFile("temp");
			}
			pro_formField.put("strSid", multiRequest.getParameter("strSid"));
			
			pro_formField.put("websvrpwd", multiRequest.getParameter("websvrpwd"));
			
			pro_uploadField.put("file",file);
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public String getValue(String param){
		return pro_formField.get(param);
	}
	
	public MultipartFile getMultipartFile(String param){
		return pro_uploadField.get(param);
	}
}
